package MonteCarlo;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class ReadFile {
	/**
	 * Read the file which name is given in argument
	 * @param fileName : The name of the file to read
	 * @return A list of String[], each element of the list is a line of the file, each element of each Strin[] 
	 * is a word of the given line.
	 */
	public static List<String[]> readFile(String fileName) throws IOException, FileNotFoundException
	{
		List<String[]> ret = new ArrayList<String[]>();
		String line = "";
		String[] options;
		BufferedReader file = null;
		
		try
		{
			file = new BufferedReader(new FileReader(new File(fileName)));
		}
		catch(FileNotFoundException e)
		{
			file = null;
			throw new FileNotFoundException("File not found : " + fileName);
		}
		
		if(file != null)
		{
			do
			{
				line = file.readLine();
				if(line != null)
				{
					options = line.split(" ");
					ret.add(options);
				}
			} while(line != null);
		
			file.close(); 
		}
		
		return ret;
	}
}
